package com.example.doer.reading.AppDataModel;

import android.content.Context;
import android.widget.Toast;

import com.ab.http.AbHttpUtil;
import com.ab.http.AbStringHttpResponseListener;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created by 严旭江 on 2017/7/11.
 */
//当一个类实现了Seializable接口
// （该接口仅为标记接口，不包含任何方法定义），表示该类可以序列化，
// 序列化的目的是将一个实现了Serializable接口的对象可以转换成一个字节序列，保存对象的状态
//Theme类其中的一个或多个问题
//↓↓
//问题   Question    =  =     Topic  话题--->问题
public class Topic implements Serializable {
    private String topicID;//话题的ID
    private int userID;//话题--用户ID
    private String topicCatagory;//话题类别--------->TopicFromTheme
    private String catagoryLogoPath;//theme的Logo
    private String topicName;//话题名-------------->问题名字
    private String topicContent;//话题内容------------>问题内容
    private int collectionCount;//收藏数目
    private int replyCount;//回复数目----------->算的评论与每个回复评论的数目
    private TopicReply aTopicReply;
    /**
     *
     * @param theTopicID topic的ID
     * @param theCatagory 话题类别-------->问题来自于 即Theme
     * @param theCatagoryLogoPath   话题的logopath
     * @param theTopicName 问题的标题
     * @param theTopicContent 话题的描述
     * @param theCollectCount 关注/收藏数目
     * @param theReplyCount 回复数目
     */
    public Topic (String theTopicID,
                  String theCatagory,
                  String theCatagoryLogoPath,
                  String theTopicName,
                  String theTopicContent,
                  int theCollectCount,
                  int theReplyCount
    )
    {
        this.topicID = theTopicID;
        this.topicCatagory = theCatagory;
        this.catagoryLogoPath = theCatagoryLogoPath;
        this.topicName = theTopicName;
        this.topicContent = theTopicContent;
        this.collectionCount = 0;
        this.replyCount = 0;
        this.collectionCount = theCollectCount;
        this.replyCount = theReplyCount;
        aTopicReply = null;
    }
    /**
     * @param theTopicID topic的ID
     * @param theCatagory 话题类别-------->问题来自于 即Theme
     * @param theCatagoryLogoPath   话题的logopath
     * @param theTopicName 问题的标题
     * @param theTopicContent 问题的描述
     * @param theCollectCount 关注/收藏数目
     * @param theReplyCount 回复数目
     * @param  theTopicReply Topic(Question)的一个回复
     */
    public Topic (String theTopicID,
                  String theCatagory,
                  String theCatagoryLogoPath,
                  String theTopicName,
                  String theTopicContent,
                  int theCollectCount,
                  int theReplyCount,
                  TopicReply theTopicReply
    )
    {
        this.topicID = theTopicID;
        this.topicCatagory = theCatagory;
        this.catagoryLogoPath = theCatagoryLogoPath;
        this.topicName = theTopicName;
        this.topicContent = theTopicContent;
        this.collectionCount = 0;
        this.replyCount = 0;
        this.collectionCount = theCollectCount;
        this.replyCount = theReplyCount;
        this.aTopicReply = theTopicReply;
    }



    //getter
    public String getTopicID() {
        return topicID;
    }
    public String getTopicCatagory(){return this.topicCatagory;}
    public int getUserID(){return this.userID;}
    public String getTopicName(){return this.topicName;}
    public String getTopicContent(){return this.topicContent;}
    public int getCollectionCount(){return this.collectionCount;}
    public int getReplyCount(){return this.replyCount;}
    public void setTopicID(String topicID) {
        this.topicID = topicID;
    }
    public void setTopicContent(String theContent){
        this.topicContent = theContent;
    }
    //public void setDislikeCount(int theDislikeCount){this.dislikeCount = theDislikeCount;}
    public void setCollectionCount(int theCollectionCount){
        this.collectionCount = theCollectionCount;
    }
    public void setUserID(int userID) {
        this.userID = userID;
    }
    public void setTopicCatagory(String topicCatagory) {
        this.topicCatagory = topicCatagory;
    }
    public String getCatagoryLogoPath() {
        return catagoryLogoPath;
    }
    public void setCatagoryLogoPath(String catagoryLogoPath) {
        this.catagoryLogoPath = catagoryLogoPath;
    }
    public void setTopicName(String topicName) {
        this.topicName = topicName;
    }
    public TopicReply getaTopicReply() {
        return aTopicReply;
    }
    public void setaTopicReply(TopicReply aTopicReply) {
        this.aTopicReply = aTopicReply;
    }
    public void setReplyCount(int theReplyCount){this.replyCount= theReplyCount;}
    public static Topic getTopicFromServer(final Context context){
        AbHttpUtil abHttpUtil= AbHttpUtil.getInstance(context);
        String url="http://192.168.191.1/Reading/InfoDoServlet?Action=down&UserID=15271901633";
        abHttpUtil.get(url, new AbStringHttpResponseListener() {
            @Override
            public void onSuccess(int i, String s) {
                JSONObject jsonObject= null;
                try {
                    jsonObject = new JSONObject(s);
                    JSONArray jsonArray=jsonObject.getJSONArray("user");
                    JSONObject object=jsonObject.getJSONObject("user");
                    Toast.makeText(context,object.getString("userName"),Toast.LENGTH_LONG).show();;
                    String test="hello";

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onStart() {

            }

            @Override
            public void onFinish() {

            }

            @Override
            public void onFailure(int i, String s, Throwable throwable) {

            }
        });
        return null;
    }
}//end class
